import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Leetcode396 {
    static class DTO {

        Long id;
        List<Integer> list;

        public DTO(List<Integer> list) {
            this.list = list;
        }
    }

    public static void main(String[] args) {


    }

    public static int maxRotateFunction(int[] nums) {
        int n = nums.length;
        int res = 0;

        int sum = 0;
        for (int i = 0; i < n; i++) {
            res += nums[i] * i;
            sum += nums[i];
        }

        int parent = res;
        for (int i = 1; i < n; i++) {
            parent = parent + sum - n * nums[n - i];

            res = Math.max(parent, res);
        }

        return res;
    }

}
